﻿@{
    Layout = null;
}
<!DOCTYPE html>

<html>
<head>
    <title>相册</title>
    <link href="@Url.Content("~/Areas/User/Css/all2.css")" rel="stylesheet" type="text/css" />
    <link href="/JS/artDialog/skins/Dialog.css" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Areas/User/Css/shop.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Areas/User/Css/pager.css")" rel="stylesheet" type="text/css" />
    <script src="../../../../JS/artDialog/jquery.artDialog.source.js?skin=simple" type="text/javascript"></script>
    <script src="../../../../JS/artDialog/dialogHelper.js"  type="text/javascript"></script>
    <script src="../../../../JS/fanhui.js" type="text/javascript"></script>
</head>
<body>

 <div class="rightbar mt10">
        <ul class="tittab">
            <li class="tcurrent"><a hidefocus="" href="/User/Images/Album">管理相册</a></li>
            <li><a hidefocus="" href="/User/Images/ImgUploadBatch">上传图片</a></li>
           
        </ul>
        <p class="subtitle">
            <b><a href="/User/Images/Album">所有相册</a> &gt; <i class="orange">
                @ViewBag.alumnName</i></b></p>
        <ul class="phoshow" style="height: 170px; overflow: hidden;">
            <li class="phone"><a href="#">
                <img src="@ViewBag.coverFile" width="100" height="100" /></a></li>
            <li class="fd-left ml10 mt15">
                <p>
                    <span class="f14"><b class="orange">
                        @ViewBag.alumnName
                    </b>共有 <b class="red1">
                        @ViewBag.picCount</b> 张图片</span> <span class="blue reset1 ml10"><a href="###" onclick="editAlbum();">
                            修改相册属性</a></span></p>
                <p class="mt10">
                    <span class="orange-btn"><a href="/User/Images/ImgUploadBatch?album=@ViewBag.alumnId">添加新图片</a></span></p>
            </li>
        </ul>
        <div class="mt10 fd-left ml20">
            <span class="fd-left">
                <input name="allselect" type="checkbox" class="none" />&nbsp;&nbsp;全部选择 </span>
            <p class="fd-left blue">
                <span class="reset ml10"><a href="###" onclick="setCoverFile();">设置封面</a></span>
                <span class="blue reset ml10"><a href="###" onclick="moveAlbum();">移动</a></span>
                    <span class="blue reset ml10"><a href="###" onclick="recommendImage();">推荐</a></span>
                    <span class="blue reset ml10"><a href="###" onclick="del();">删除</a></span></p>
            <span class="fd-left ml10">当前排序：
                <select name="ddlorder" id="ddlorder1">
                    <option value="1">新相片在前</option>
                    <option value="0">新相片在后</option>
                </select>
            </span><span class="fd-left ml10">相册权限设置：
                <select name="ddlorder" id="ddlIsShow">
                    <option value="0">访客查看</option>
                    <option value="1">仅自己查看</option>
                </select>
            </span>
        </div>
        <div class="album mt10">
                 @foreach (var single in @Model.Rows)
                 {
                    <dl>
                        <dt><a href="/User/Images/AlbumImageDetail?id=@single["Id"]&album=@single["AlbumId"]" title="@single["Title"].ToString()">
                            <img src="@Common.GDI.ResizeImage(single["Name"].ToString(),100)" alt="@single["Title"].ToString()" /></a></dt>
                        <dd>
                            <input type="checkbox" class="fd-left none" name="chkpic" value="@single["Id"]"
                                lang="@single["Name"]" />
                            <span onclick="editTitle(this)" title="@single["Title"].ToString()" class="fd-left ml10">
                                 @Common.StringManager.SubByte(single["Title"], 8)</span>
                            <input type="hidden" value='@single["Title"]' />
                            <div style="display: none; padding: 2px 0px;">
                                <input onblur="hideDiv(this)" name="editTitle@single["Id"]" value="@single["Title"]"
                                    type="text" style="width: 63px; margin-left: 5px;" />
                            </div>
                        </dd>
                    </dl>
                    }
        </div>
        <div class="mt10 fd-right ml20">

        </div>
    </div>

     <script type="text/javascript">
    $(function () {
            $(".mt10 dt").mouseover(function () {
                $(this).css("border-color", "red");
            });
            $(".mt10 dt").mouseout(function () {
                $(this).css("border-color", "#d8d8d8");
            });
             $("#ddlIsShow option[value='@ViewBag.isShow']").attr("selected", "true");
            //var order = Request.QueryString("order");
            $("#ddlorder1 option[value='@Common.RequestHelper.GetString("order")']").attr("selected", "true");
            ///全选
            $("input[name='allselect']").click(function () {
                if ($(this).attr("checked")) {
                    $("input[name='chkpic']").attr("checked", true);
                } else {
                    $("input[name='chkpic']").removeAttr("checked");
                }
            });            
            $("#ddlorder1").change(function () {
                location = "/User/AlbumInfo?id=@ViewBag.alumnId&order=" + $(this).val();
            });
            $("#ddlIsShow").change(function () {
                $.ajax({
                    type: "POST",
                    url: "/Shop/ashx/AlbumHandler.ashx?action=isshow&value=" + $(this).val() + "&alumnid="+@ViewBag.alumnId,
                    data: $("form").serialize(),
                    cache: false,
                    dataType: "text",
                    error: function () {
                    jQuery.dialogHelper.alert("网络忙，请稍后再试！", "alert");                       
                    },
                    success: function (msg) {
                        if (msg=="1") {
                        jQuery.dialogHelper.alert("相册权限设置成功！", "success", "okSuccess");    
                        } 
                        else {
                    jQuery.dialogHelper.alert("网络忙，相册权限设置失败！", "alert");                           
                        }
                    }
                });
            });
        });
        
        var tempTitle;
        var AlbumImgId;
        var editTitle = function(sender){
            $(sender).parent().children("span").hide();
            $(sender).parent().children("div").show();
            tempTitle = $(sender).parent().children("input[type='hidden']").val();
            $(sender).parent().children("div").children("input").focus();
            AlbumImgId = $(sender).parent().children("input").val();
        }
        var hideDiv = function(sender){
            $(sender).parent().parent().children("span").show();
            $(sender).parent().hide();
            if(tempTitle != $(sender).val()){
                $.ajax({
                    type:"Post",
                    url:"/User/Images/AlbumImgNameEdit",
                    dataType:"text",
                    data:"name=" + $(sender).val() + "&id=" + AlbumImgId,
                    error:function(){
                    jQuery.dialogHelper.alert("网络忙，请稍后再试！", "alert");
                    },
                    success:function(msg){
                        if(msg == 0){
                        jQuery.dialogHelper.alert("图片名修改成功！", "success", "okSuccess");                              
                        }
                    }
                });
            }
        }
        function moveAlbum() {
            var id = "";
            var obj = $("input:checked[name='chkpic']");
            if (obj.length == 0) {
                    jQuery.dialogHelper.alert("请选择要移动的图片！", "alert");
            }else{
            $("input:checked[name='chkpic']").each(function () {
                id += $(this).val();
                id += ",";
            });
            var option = { id: '1233' };
            jQuery.dialogHelper.open("/Shop/MoveImage.aspx?albumid=<%=alumnId %>&image=" + id, option);   
            }     
        }
        function move(imageid,newalbumid) {
            $.ajax({
                type: "POST",
                url: "/Shop/MoveImage.aspx" ,
                data:"albumid=" @ViewBag.alumnId + "&image=" + imageid+"&ddlalumn="+newalbumid,
                cache: false,
                dataType: "text",
                error: function () {
                    jQuery.dialogHelper.alert("网络忙，请稍后再试！", "alert");
                },
                success: function (msg) {
                    if (msg != "1") {
                        jQuery.dialogHelper.alert("图片移动失败!请确定所选的图片是否存在。", "alert");
                    }
                    else {
                        jQuery.dialogHelper.alert("图片移动成功！", "success", "okSuccess");    
                    }
                }
            });
        }
        ///将图片相册从相册移除
        function del() {
            var id = "";
            var obj = $("input:checked[name='chkpic']");
            if (obj.length == 0) {
                    jQuery.dialogHelper.alert("请选择要操作的图片！", "alert");
            }else{
            $("input:checked[name='chkpic']").each(function () {
                id += $(this).val();
                id += ",";
            });         
            $.get("/User/Images/AlbumOperator?action=remove&id=" + id + "&alumnid=<%=alumnId %>", function (data) {
                location.reload();
            })
            }
        }

        function setCoverFile() {        
            if ($("input:checked[name='chkpic']").length != 1) {
                    jQuery.dialogHelper.alert("请选择一个图片作为相册的封面！", "alert");
            }
            else{
                var id = $("input:checked[name='chkpic']").attr("lang");        
                $.get("/User/Images/AlbumOperator?action=cover&image=" + id + "&alumnid=@ViewBag.alumnId", function (data) {
                    jQuery.dialogHelper.alert("封面设置成功！", "success", "okSuccess");       
                })             
            }  
        }

        function recommendImage() {
         if ($("input:checked[name='chkpic']").length < 1) {
                    jQuery.dialogHelper.alert("请选择要推荐的图片！", "alert");
            }else{
               var id="";
               $("input:checked[name='chkpic']").each(function () {
                    id += $(this).val();
                    id += ",";
                });            
                $.get("/User/Images/AlbumOperator?action=recommend&albumid=<%=alumnId %>&imageid="+id, function (data) {                
                    if(data==1)
                    {
                        jQuery.dialogHelper.alert("图片推荐成功！", "success");
                    }
                })
            }
        }

        function editAlbum() {
            var option = { id: '1231' };
            jQuery.dialogHelper.open("/User/AlbumEdit?id=@ViewBag.alumnId", option);
        }
        function okSuccess() {
            $.dialogHelper.close();
            location.reload();
        }
        function AlbumEdit() {
            $.ajax({
                type: "POST",
                url: "/User/Images/AlbumEdit",
                data: { "albumName": $("#txt_AlbumName").val(),"id":@ViewBag.alumnId },
                dataType: "text",
                success: function (result) {
                    jQuery.dialogHelper.close(1231);
                    if (result.indexOf("成功") != -1) {
                        jQuery.dialogHelper.alert(result, "success", "okSuccess");  //状态包括:success,smile,alert
                    } else {
                        jQuery.dialogHelper.alert(result, "alert");
                    }
                },
                error: function () {
                    jQuery.dialogHelper.close(1231);
                    jQuery.dialogHelper.alert("网络忙，请稍后再试！", "alert");
                }
            });
        }
    </script>
</body>
</html>